#ifdef __cplusplus
extern "C"
{
#endif

// LuaJIT must be installed
#ifndef LUA_R_INCL
# include "luajit-2.0/lauxlib.h"
# include "luajit-2.0/lualib.h"
# include "luajit-2.0/lua.h"
#else
# include "lauxlib.h"
# include "lualib.h"
# include "lua.h"
#endif

#if LUA_VERSION_NUM < 502
void luaL_set_cfuncs (lua_State *L, const luaL_Reg *l);
#else
# define luaL_set_cfuncs(L, l) luaL_setfuncs((L), (l), 0)
# ifndef luaL_register // compatible to legacy luaL_register function
#  define luaL_register(L, name, l) (luaL_newlib(L, l), lua_pushvalue(L, -1), lua_setglobal(L, name))
# endif
#endif

// compatible to legacy luaL_checkint and luaL_optint
#if LUA_VERSION_NUM >= 503 && !defined(LUA_COMPAT_APIINTCASTS)
# define luaL_checkint(L, n)	((int)luaL_checkinteger(L, (n)))
# define luaL_optint(L, n, d)	((int)luaL_optinteger(L, (n), (d)))
#endif

#ifdef __cplusplus
}
#endif
